<?
    final class Principio_Model_AccountLink implements PrincipioLab_IDAble
    {
        use PrincipioLab_TCollection;

        private $model_spa;
        private $model_account;
        private $ext_number;


        public function __construct(Principio_Model_Spa $model_spa, Principio_Model_Account $model_account, $ext_number)
        {
            $this->model_spa = $model_spa;
            $this->model_account = $model_account;
            $this->ext_number = intval($ext_number);
        }


        public function _getID() { return $this->ext_number; }


        public static function makeCollection(array $values = null, PrincipioLab_IComparator $comparator = null)
        {
            $collection = static::getLinkedList($comparator);

            $model_spa = $values['model_spa'];

            foreach ($values['values'] as $value)
            {
                $collection->addItem(
                    new Principio_Model_AccountLink(
                        $model_spa,
                        (intval($value['account_id']) == -1) ? $model_spa->getModelCompany()->createAccount() : Principio_Model_AccountMapper::fetch($value['account_id']),
                        $value['ext_id']
                    )
                );
            };

            return $collection;
        }


        public function getModelSpa() { return $this->model_spa; }
        public function getModelAccount() { return $this->model_account; }


        public function setModelAccount(Principio_Model_Account $model_account)
        {
            $this->model_account = $model_account;
            return $this;
        }


        public function getExtNumber() { return $this->ext_number; }

        public function add() { return Principio_Model_AccountLinkMapper::insert($this); }
        public function save() { return Principio_Model_AccountLinkMapper::update($this); }
        public function delete() { return Principio_Model_AccountLinkMapper::delete($this); }
    }
?>